<?php

if (!defined('BASEPATH'))
    exit('No direct script access allowed');

class Tai_khoan extends CI_Controller {

    public function __construct() {
        parent::__construct();
        $this->load->library('session');
        $this->load->model('User_model', 'user');
    }

    public function index() {
        $this->dang_nhap();
    }

    public function dang_nhap($submit=null) {
        $submit = $this->input->post('mysubmit');
        if ($submit == null)
            $this->load->view('backend/dang_nhap');
        else {
            $check = $this->user->check();
            if ($check == TRUE) {
                $data = array(
                    'username' => $this->input->post('username'),
                    'logged_in' => TRUE
                );
                $this->session->set_userdata($data);
                redirect('ql/noi_dung', 'location');
            } else {
                $data['message'] = "Tên tài khoản hoặc mật khẩu không chính xác.";
                $this->load->view('backend/dang_nhap', $data);
            }
        }
    }

    public function dang_xuat() {
        $this->session->sess_destroy();
        redirect('ql/tai_khoan/dang_nhap', 'location');
    }

}

?>
